package insight.google.game.era.data;


import java.util.Date;
import java.util.HashMap;
import java.util.List;

import javax.jdo.annotations.IdentityType;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;

import org.directwebremoting.proxy.ScriptProxy;

/**
 * JDO class for User entity.
 * @author MMC
 *
 */
@PersistenceCapable(identityType = IdentityType.APPLICATION,detachable="true")
public class Player {
	@PrimaryKey
	@Persistent
	private String userID;
	
	@Persistent
	private String userFirstName;
	
	@Persistent
	private String userLastName;
	
	@Persistent
	private Date firstJoinDate;
	
	@Persistent
	private Date lastLoginTime;
	
	@Persistent
	private int lastLogoutTime;
	
	@Persistent
	private int winTime;
	
	@Persistent
	private int gameTime;
	
	@Persistent
	private List<GameResult> gameResultHistory;
	
	private Host host;
	private Room room;
	private Date loginTime;
	private Date joinRoomTime;
	private Date quitRoomTime;
	private int state;
	

	
	public Player(String userID, String userFirstName, String userLastName) {
		this.userID = userID;
		this.userFirstName = userFirstName;
		this.userLastName = userLastName;
	}
	
	
	
	/**
	 * @return the userID
	 */
	public String getUserID() {
		return userID;
	}

	/**
	 * @param userID the userID to set
	 */
	public void setUserID(String userID) {
		this.userID = userID;
	}

	/**
	 * @return the userFirstName
	 */
	public String getUserFirstName() {
		return userFirstName;
	}

	/**
	 * @param userFirstName the userFirstName to set
	 */
	public void setUserFirstName(String userFirstName) {
		this.userFirstName = userFirstName;
	}

	/**
	 * @return the userLastName
	 */
	public String getUserLastName() {
		return userLastName;
	}

	/**
	 * @param userLastName the userLastName to set
	 */
	public void setUserLastName(String userLastName) {
		this.userLastName = userLastName;
	}

	/**
	 * @return the firstJoinDate
	 */
	public Date getFirstJoinDate() {
		return firstJoinDate;
	}

	/**
	 * @param firstJoinDate the firstJoinDate to set
	 */
	public void setFirstJoinDate(Date firstJoinDate) {
		this.firstJoinDate = firstJoinDate;
	}

	/**
	 * @return the lastLoginTime
	 */
	public Date getLastLoginTime() {
		return lastLoginTime;
	}

	/**
	 * @param lastLoginTime the lastLoginTime to set
	 */
	public void setLastLoginTime(Date lastLoginTime) {
		this.lastLoginTime = lastLoginTime;
	}

	/**
	 * @return the lastLogoutTime
	 */
	public int getLastLogoutTime() {
		return lastLogoutTime;
	}

	/**
	 * @param lastLogoutTime the lastLogoutTime to set
	 */
	public void setLastLogoutTime(int lastLogoutTime) {
		this.lastLogoutTime = lastLogoutTime;
	}

	/**
	 * @return the gameResultHistory
	 */
	public List<GameResult> getGameResultHistory() {
		return gameResultHistory;
	}

	/**
	 * @param gameResultHistory the gameResultHistory to set
	 */
	public void setGameResultHistory(List<GameResult> gameResultHistory) {
		this.gameResultHistory = gameResultHistory;
	}

	/**
	 * @return the winTime
	 */
	public int getWinTime() {
		return winTime;
	}

	/**
	 * @param winTime the winTime to set
	 */
	public void setWinTime(int winTime) {
		this.winTime = winTime;
	}

	/**
	 * @return the gameTime
	 */
	public int getGameTime() {
		return gameTime;
	}

	/**
	 * @param gameTime the gameTime to set
	 */
	public void setGameTime(int gameTime) {
		this.gameTime = gameTime;
	}
	
	public void quit() {
		if (room != null) {
			//room.quit(this);
		}
		if (host != null) {
			host.quit(this);
		}
		room = null;
		host = null;
	}
	
	public void setRoom(Room room) {
		this.room = room;
	}
	
	public void setHost(Host host) {
		this.host = host;
	}
	
	public Room getRoom() {
		return room;
	}
	
	public Host getHost() {
		return host;
	}
	
	/**
	 * overwrite toString() method.
	 */
	public String toString() {
		StringBuffer buffer = new StringBuffer();
		buffer.append("GAME USER: " 
				+ "USER ID : " + userID 
				+ ", Name : " + (userFirstName + " " + userLastName)
				+ ", Played Game " + gameTime + "times, "
				+ " win " + winTime + "times"
				+ " Logintime:" + loginTime
				+ "Host: " + host
				+ "Room: " + room);
		return buffer.toString();
	}
}
